<template>
  <el-container>
    <el-header>
      <div>
        <img src="@/assets/logo.png">
        <span style="color:white">Vue练手</span>
      </div>
      <el-button type="" @click="logout">推出</el-button>
    </el-header>
    <el-container>
      <el-aside :width="isCollapse?'64px':'200px'">
        <div class="toggle-button" @click="toggleCollapse"> |||</div>
        <el-menu background-color="#313743" text-color="white" :unique-opened=true
        :collapse="isCollapse" :collapse-transition=false router :default-active="$route.path"
        >
          <!-- 一级菜单 -->
          <el-submenu :index="item.id+''" v-for="item in menulist" :key="item.id">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{item.authName}}</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item :index="'/'+subItem.path" v-for="subItem in item.children" :key="subItem.id">
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{subItem.authName}}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>

      </el-aside>
      <el-main><router-view></router-view></el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  data () {
    return {
      menulist: [],
      isCollapse: false
    }
  },
  created () {
    this.getMenuList()
  },
  methods: {
    logout () {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    async getMenuList () {
      const { data: res } = await this.$http.get('menus')
      // console.log(res)
      // this.$http.get('menus')
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.menulist = res.data
    },
    toggleCollapse () {
      this.isCollapse = !this.isCollapse
    }

  }
}
</script>

<style lang="less" scoped>
.el-header {
  background-color: #363d40;
  display: flex;
  justify-content: space-between;
  padding-left: 10px;
  align-items: center;
  font-size: 20px;

  > div {
    padding-left: 10px;
    display: flex;
    align-items: center;
  }
  img {
    width: 50px;
    height: 50px;
    margin-right: 15px;
  }
}
.el-aside {
  background-color: #313743;

  .el-menu{
    border-right:none ;
  }
}
.el-main {
  background-color: #acdaf8;
}

section {
  width: 100%;
  height: 100%;
}

.toggle-button{
  background-color: rgba(6, 95, 228, 0.63);
  font-size: 10px;
  line-height: 24px;
  color: wheat;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}
</style>
